#include <iostream>

#include <boost/asio.hpp>
/*
#include "LocalConnection.h"
#include "EventEngine.h"
#include "NetworkServerConnection.h"
*/

#include "NetworkServerConnection.h"
#include "NetworkClientConnection.h"
#include "EventEngine.h"
#include "TestEvent.h"

void injectEvent(boost::shared_ptr<ENE::EventEngine> eventEngine, ChuGame::GameState& state)
{
	boost::shared_ptr<TestEvent> event(new TestEvent(state.getClock().getTick(), 1));
	eventEngine->handleEvent(event);
}

int main()
{	
	try
	{
		//*
		ChuGame::GameState state;

		ENE::NetworkServerConnection serverConnection(2300);
		serverConnection.listen();
		serverConnection.start();
		
		ENE::NetworkClientConnection clientConnection;
		clientConnection.connect("localhost", "2300");
		clientConnection.start();

		boost::shared_ptr<ENE::EventEngine> serverEventEngine(new ENE::EventEngine(state, serverConnection));
		boost::shared_ptr<ENE::EventEngine> clientEventEngine(new ENE::EventEngine(state, clientConnection));

		serverConnection.setEventEngine(serverEventEngine);
		clientConnection.setEventEngine(clientEventEngine);

		//*/
		while(1)
		{
			clientEventEngine->update(1);
			serverEventEngine->update(1);
		}
	}
	catch(boost::system::system_error e)
	{
		std::cout << e.what() << std::endl;
	}


	return 0;
}